package io.github.kimmking.javapuzzles;

/**
 * Description for this class.
 *
 * @Author : kimmking(kimmking@apache.org)
 * @create 2024/1/20 22:19
 */

public class JavaPuzzle7 {

    static boolean flag = false;
    public static void main(String[] args) {

//        final String[] arr = {"1"};
        final Integer[] pp = {10}; //Integer b = 11;
//        final int[] pp = {10};
 //       final float[] pp ={1.0f};
//        final StringBuilder s = new StringBuilder("a");

//        p[0] = 1001;
//        pp[0] = 2001;

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (!flag) {
                   // System.out.println("1"); // 停止
                    //arr[0] = "2"; // 停止
                   // pp[0] = 11;  // 停止
                    pp[0] = 11; // 死循环
                    // read barrier
                    //s.append("bc"); // 停止
                    //tt(); // tt内情况同上

//                    try {
//                        Thread.sleep(0);
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
                }
            }
        }
        , "t1").start();

        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        new Thread( () -> {
            flag = true;
            System.out.println("t2 done.");
        }, "t2").start();


    }

//    static void tt(){
//        Integer a = 1;
//    }

}
